/*
 * Copyright (C) 2015 Daniel Uppenkamp
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.maurersmarbles;

import com.google.common.base.Preconditions;

/**
 *
 * @author Daniel Uppenkamp
 */
public class Move {

    /**
     * The marble number for the move.
     */
    protected int marbleNumber;
    /**
     * The new marble board index for the move.
     */
    protected int newMarbleBoardIndex;
    /**
     * The player number for the move.
     */
    protected int playerNumber;

    /**
     * Creates a new Move.
     *
     * @param playerNumber the player number
     * @param marbleNumber the marble number
     * @param newMarbleBoardIndex the new marble board index
     */
    public Move(int playerNumber, int marbleNumber, int newMarbleBoardIndex) {
        this.playerNumber = playerNumber;
        this.marbleNumber = marbleNumber;
        this.newMarbleBoardIndex = newMarbleBoardIndex;
    }

    /**
     * Creates a new Move.
     *
     * @param marble the marble to create the move for
     * @param newMarbleBoardIndex the new marble board index
     */
    public Move(Marble marble, int newMarbleBoardIndex) {

        Preconditions.checkNotNull(marble, "Null marble");

        this.playerNumber = marble.getPlayerNumber();
        this.marbleNumber = marble.getMarbleNumber();
        this.newMarbleBoardIndex = newMarbleBoardIndex;

    }

    /**
     * Returns the marble number.
     *
     * @return the marble number
     */
    public int getMarbleNumber() {
        return marbleNumber;
    }

    /**
     * Returns the new marble board index.
     *
     * @return the new marble board index
     */
    public int getNewMarbleBoardIndex() {
        return newMarbleBoardIndex;
    }

    /**
     * Returns the player number.
     *
     * @return the player number
     */
    public int getPlayerNumber() {
        return playerNumber;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 31 * hash + this.marbleNumber;
        hash = 31 * hash + this.newMarbleBoardIndex;
        hash = 31 * hash + this.playerNumber;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Move other = (Move) obj;
        if (this.marbleNumber != other.marbleNumber) {
            return false;
        }
        if (this.newMarbleBoardIndex != other.newMarbleBoardIndex) {
            return false;
        }
        if (this.playerNumber != other.playerNumber) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getClass().getName() + "[playerNumber=" + playerNumber + ",marbleNumber=" + marbleNumber + ",newMarbleBoardIndex=" + newMarbleBoardIndex + "]";
    }

}
